﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace Wicresoft.SMS.Web
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    public class AuthoriseMetadataProviderAttribute : Attribute
    {
        private Type _providerType;
        public AuthoriseMetadataProviderAttribute(Type providerType)
        {
            _providerType = providerType;
        }

        public IAuthoriseMetadataProvider CreateIAuthoriseMetadataProvider(PropertyInfo property , params object[] args)
        {
            if (_providerType.GetInterface("IAuthoriseMetadataProvider") == null)
                throw new Exception("custom provider is not a implement of IAuthoriseMetadataProvider");
            if (property == null)
                throw new ArgumentNullException("property should not be null");
            IAuthoriseMetadataProvider provider = Activator.CreateInstance(_providerType, args) as IAuthoriseMetadataProvider;
            return provider;
        }
    }
}